import Vue from "vue";
import Vuex from "vuex";
import { setItem, getItem } from "@/utils/storage";

Vue.use(Vuex);
const TOKEN_KEY = "TOUTIAO_USER";
export default new Vuex.Store({
    state: {
        //用户的token
        user: getItem(TOKEN_KEY) || {},
    },
    mutations: {
        //设置token
        setUser(state, data) {
            //设置给state
            state.user = data;
            //存储到本地
            setItem(TOKEN_KEY, data);
        },
    },
    getters: {
        //建立快捷访问
        token: (state) => state.user.token,
    },
    actions: {},
    modules: {},
});